home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d3 / rettig.arc / TRSOURCE.EXE / DEPDB.C < prev    next >
C/C++ Source or Header  |  1990-10-22  |  1KB  |  51 lines

  1. /*********
  2. *
  3. * DEPDB.C
  4. *
  5. * by Ralph Davis
  6. * modified by Tom Rettig
  7. *
  8. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  9. *
  10. *********/
  11.  
  12. /* DEPDB : Depreciation by declining-balance method
  13.  
  14.             Computes depreciation calculated as percent
  15.                of current value.
  16.  
  17.             SYNTAX:  DEPDB(value, rate, periods)
  18.       
  19.                    where value =   current value
  20.                          rate  =   depreciation rate per period
  21.                          periods = number of periods in calculations
  22.  
  23.             RETURNS:  depreciation over specified period of time.
  24. */
  25.  
  26. #include "trlib.h"
  27.  
  28. TRTYPE depdb()
  29. {
  30.    if ( PCOUNT==3 && ISNUM(1) && ISNUM(2) && ISNUM(3) )
  31.    {
  32.       double value   = _parnd(1);
  33.       double rate    = _parnd(2);
  34.       int    periods = (int)_parnd(3);
  35.    
  36.       double depr    = 0;
  37.       int    i;
  38.    
  39.       for (i = 0; i < periods; i++)
  40.       {
  41.           depr  += value * rate;   /* Depreciation = value times
  42.                                                      rate of depreciation */
  43.           value *= (1.0 - rate);   /* New value = old value reduced
  44.                                                   by rate of depreciation */
  45.       }
  46.       _retnd(depr);
  47.    }
  48.    else
  49.       _retnd( (double)ERROR );
  50. }
  51.